import { list } from "../../api/member";
import { isNull } from "../../utils/util";
Page({

    data: {
        seller: [],
        name: '',
        id: null,
        activ: 2,
        offsetLeft: 5,
        query: {
            pageNum: 1,
            pageSize: 20,
            keyword: '',
            type: 2
        },
        timer: null
    },
    onShow() {
        this.data.query.pageNum = 1
        this.data.pageSize = 20
        this.setData({
            seller: [],
            [`query.pageNum`]: this.data.query.pageNum,
            [`query.pageSize`]: this.data.query.pageSize,
        })
        this.search();
    },
    onPullDownRefresh() {
        wx.showLoading({
            title: '加载中',
        })
        this.data.seller = []
        this.data.query.pageNum = 1
        this.setData({
            [`query.pageNum`]: this.data.query.pageNum,
            seller: this.data.seller
        })
        setTimeout(() => {
            this.search(() => {
                wx.hideLoading()
                wx.stopPullDownRefresh()
            })
        }, 1000)
    },
    onReachBottom() {
        this.data.query.pageNum += 1
        this.setData({
            [`query.pageNum`]: this.data.query.pageNum
        })
        this.search()
    },
    tapTab(e) {
        this.setData({
            offsetLeft: e.currentTarget.offsetLeft,
            activ: e.currentTarget.dataset.index
        })
        this.data.query.type = e.currentTarget.dataset.index
        this.search();
    },
    search(callBack) {
        list(this.data.query).then(res => {
            console.log(res);
            this.setData({
                seller: res.data.data
            })

        })
        //如果回调函数存在，则执行该回调函数。
        callBack && callBack()
    },
    keyword(e) {
        clearTimeout(this.data.timer)
        this.data.timer = setTimeout(() => {
            this.setData({
                [`query.keyword`]: e.detail.value
            })
            this.search()
        }, 500)
    },
    clear() {
        this.setData({
            [`query.keyword`]: ""
        })
        this.search()
    },
    add() {
        wx.navigateTo({
            url: '/pages/pagesUser/companyInfo/attestation?sellearAdd=' + true,
        })
    },

    goToDetail(e) {
        wx.navigateTo({
            url: '/pages/customer/customerDetail?id=' + e.currentTarget.dataset.id,
        })
    }
})
